package com.share.spring;

import com.share.bean.Person;
import com.share.config.SpringConfig;
import com.share.mapper.PersonMapper;
import com.share.mapper.StudentMapper;
import com.share.service.PersonService;
import com.share.service.PersonServiceImpl;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * author:caifan
 * date:2019/8/23
 */
public class IOCExample_01 {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        PersonService personService = (PersonService) context.getBean(PersonServiceImpl.class);
        System.out.println(personService.getPersonByName("1111"));


        /**
         * 通过实现BeanDefinitionRegistryPostProcessor只能注册非接口
         */
        AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext("com.share");
        Person personBean = context1.getBean(Person.class);
        System.out.println(personBean.toString());
        PersonMapper personMapper = (PersonMapper) context.getBean(PersonMapper.class);
        System.out.println(personMapper.getClass());
        StudentMapper studentMapper = (StudentMapper) context.getBean(StudentMapper.class);
        System.out.println(studentMapper.getClass());
    }
}
